package kassiopeia.agent;

import kassiopeia.agent.io.MessageReceiver;
import kassiopeia.commons.io.Message;
import kassiopeia.commons.io.TaskMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TaskReceiver implements MessageReceiver {

    @Autowired
    private KassiopeiaAgent agent;

    @Override
    public void onMessage(final Message message) {
        if (message instanceof TaskMessage) {
            agent.start(((TaskMessage) message).getTask());
        }
    }

    @Override
    public Class<? extends Message>[] acceptedMessages() {
        return new Class[] {TaskMessage.class};
    }

}
